package com.simpletour.qa.service.entity;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.simpletour.qa.common.repository.LocalDateTimeAttributeConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "t_question", schema = "qa")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Question {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "question_id")
    private Integer questionId;

    @NotNull
    private Integer userId;

    @Transient
    private BaseUser user;

    @NotBlank
    private String title;

    @NotBlank
    private String content;

    @Transient
    private QuestionLikeCount questionLikeCount;

    @Transient
    private int solutionNum;

    @Convert(converter = LocalDateTimeAttributeConverter.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
}
